import { defineStore } from 'pinia';
import { store } from '@/store';

   
import { createLocalStorage } from '@/utils/cache';
 

const ls = createLocalStorage();

export interface PublicKey {
  encoded: String;
  modulus:String;
  publicExponent:String;
  uuid:String;
}

export interface loginData {
  hasPublic: boolean;
  publicKey:PublicKey;
}

export const useLoginStore = defineStore({
  id: 'app-login',
  state: (): loginData => ({
    hasPublic: false,
    publicKey: {encoded:'',modulus:'',publicExponent:'',uuid:''}
  }),
  getters: {
    hasPublicKey():boolean {
      return this.hasPublic; //!!this.localInfo?.showPicker;
    }
  },
  actions: {
    setPublic(yes: boolean,key:PublicKey) {
      this.hasPublic = yes
      this.publicKey = key
    }
  },
});

// Need to be used outside the setup
export function useLoginStoreWithOut() {
  return useLoginStore(store);
}
